package live.jialing.sip.base.util;

import live.jialing.sip.base.dict.ClassCategoryEnum;
import org.apache.commons.lang3.StringUtils;

import java.time.LocalDate;

/**
 * 学校工具类
 */
public class SchoolUtil {

    public static String convertNum(int num) {

        if (num > 9 && num < 1) {
            return null;
        }

        String[] str = new String[]{"一", "二", "三", "四", "五", "六", "七", "八", "九"};
        return str[num - 1];
    }

    /**
     * 年级名称
     *
     * @param category 班级类型
     * @param inYear   入学年份
     * @return
     */
    public static String gradeName(ClassCategoryEnum category, int inYear) {

        if (StringUtils.equals(category.name(), ClassCategoryEnum.H.name())) {
            return "高" + inYear + "级";
        } else if (StringUtils.equals(category.name(), ClassCategoryEnum.M.name())) {
            return "初" + inYear + "级";
        } else if (StringUtils.equals(category.name(), ClassCategoryEnum.S.name())) {
            return "小" + inYear + "级";
        }

        return "";
    }

    /**
     * 班级名称
     *
     * @param category 班级类型
     * @param inYear   入学年份
     * @param num      班级编号
     * @param alias    班级别名
     * @return
     */
    public static String className(ClassCategoryEnum category, int inYear, int num, String alias) {

        if (StringUtils.isNotBlank(alias)) {
            return alias;
        }

        LocalDate now = LocalDate.now();
        int grade = now.getYear() - inYear;
        // 如果过了9月，则升年级
        if (now.getMonthValue() >= 9) {
            grade++;
        }

        if (StringUtils.equals(category.name(), ClassCategoryEnum.H.name())) {
            return "高" + convertNum(grade) + num+"班";
        } else if (StringUtils.equals(category.name(), ClassCategoryEnum.M.name())) {
            return "初" + convertNum(grade) + num+"班";
        } else if (StringUtils.equals(category.name(), ClassCategoryEnum.S.name())) {
            return convertNum(grade) + "年级" + num + "班";
        }

        return null;
    }
}
